// 获取验证码
let publicObject = {
  send(idName){
    window.clearInterval(interval);
    var time=30;
    document.getElementById(idName).disabled=true;
    let interval = window.setInterval(function() {
      if ((time) <= 1) {
        document.getElementById(idName).innerHTML='发送验证码';
        document.getElementById(idName).style.backgroundColor='#259B24';
        document.getElementById(idName).style.color='#fff';
        time = 30;
        window.clearInterval(interval);
        document.getElementById(idName).disabled=false;
      }else{
        time--;
        document.getElementById(idName).innerHTML=time+'s';
        document.getElementById(idName).setAttribute("style","background-color: #eaeaea !important");
        document.getElementById(idName).style.color='#848484';
      }
    }, 1000);
  },
  intervalFun(time,timeName){
    window.clearInterval(timeName);
    timeName =window.setInterval(function(){
        let nowTime = new Date();
        let endTime = new Date(time);
        let t = endTime.getTime() - nowTime.getTime();
        if(t>0){
          let day = Math.floor(t/86400000);
          let hour=Math.floor((t/3600000)%24);
          let min=Math.floor((t/60000)%60);
          let sec=Math.floor((t/1000)%60);
          hour = hour < 10 ? "0" + hour : hour;
          min = min < 10 ? "0" + min : min;
          sec = sec < 10 ? "0" + sec : sec;
          if(day > 0){
            var json={
              day:day,
              hour:hour,
              min:min,
              sec:sec
            }
          }
          if(day <= 0 && hour > 0 ){
            var json={
              hour:hour,
              min:min,
              sec:sec
            }
          }
          if(day <= 0 && hour <= 0){
            var json={
              min:min,
              sec:sec
            }
          }
          var str=JSON.stringify(json);
          return str;
        }else{
          clearInterval(timeName);
        }
      },1000);
  },
  datedifference(sDate1, sDate2) {
    var dateSpan,
      tempDate,
      iDays;
    sDate1 = Date.parse(sDate1);
    sDate2 = Date.parse(sDate2);
    dateSpan = sDate2 - sDate1;
    dateSpan = Math.abs(dateSpan);
    iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
    return iDays;
  },
  urlStr(json){
    var params = Object.keys(json).map(function (key) {
      // body...
      return encodeURIComponent(key) + "=" + encodeURIComponent(json[key]);
    }).join("&");
    return params;
  }
}
export{
  publicObject
}
